{% extends "base.html" %}
{% block content %}
    <div class="input-group container">
        <form action="" method="post" name="article_form" id="article_form">
            {{ form.csrf_token }}
            <div class="row container">
                <div class="col-lg-6">
                    <div class="input-group">
                        <span class="input-group-addon">{{ form.title.label }}</span>
                        {{ form.title(size=50,class="form-control") }}
                        {% for error in form.errors.title %}
                            <span style="color: red;">{{ error }}</span>
                        {% endfor %}
                    </div>
                </div>
                <div class="col-lg-3 pull-right">
                    <div class="input-group ">
                        <span class="input-group-addon">{{ form.category_id.label }}</span>
                        {{ form.category_id(class="form-control",placeholder="--选择--") }}
                        {% for error in form.errors.category_id %}
                            <span style="color: red;">{{ error }}</span>
                        {% endfor %}
                    </div>
                </div>
            </div>
            <br/>

            <div class="row container">
                <div class="col-lg-6">
                    <div class="input-group">
                        <span class="input-group-addon">{{ form.tag.label }}</span>
                        {{ form.tag(size=50,class="form-control") }}
                        {% for error in form.errors.tag %}
                            <span style="color: red;">{{ error }}</span>
                        {% endfor %}
                    </div>
                </div>
                <div class="col-lg-3 pull-right">
                    <div class="input-group">
                        <span class="input-group-addon">{{ form.is_open.label }}</span>
                        {{ form.is_open(class="form-control") }}
                        {% for error in form.errors.is_open %}
                            <span style="color: red;">{{ error }}</span>
                        {% endfor %}
                    </div>
                </div>
            </div>
            <hr/>
            <p>{{ form.body(rows = 20,class="container",id = 'mceEditor') }}</p>
            {% for error in form.errors.body %}
                <span style="color: red;">{{ error }}</span>
            {% endfor %}
            <hr/>
            <input type="hidden" id='textformat' name='textformat'/>
            <button type="image" onclick="sumarticle()" class="btn btn-success">
                <span class="glyphicon glyphicon-ok-sign"></span> 提交
            </button>
        </form>
    </div>
    <br/>
    <br/>
    <br/>
{% endblock %}
{% block ext_css %}
    <link href="{{ url_for('static',filename='js/kindeditor-4.1.10/themes/simple/simple.css') }}" rel="stylesheet"
          type="text/css">
{% endblock %}
{% block script %}
    <script type="text/javascript"
            src="{{ url_for('static', filename='js/kindeditor-4.1.10/kindeditor-all-min.js') }}"></script>
    <script type="text/javascript"
            src="{{ url_for('static', filename='js/kindeditor-4.1.10/lang/zh_CN.js') }}"></script>
    <script>
        var editor;
        KindEditor.ready(function (K) {
            editor = K.create('#mceEditor', {
                uploadJson: '/upload',
                themeType: 'simple'
            });
        });
    </script>
    <script type="text/javascript">
        function sumarticle() {
            var text = editor.text();
            document.getElementById('textformat').value = text;
            document.getElementById('article_form').sumbit();
        }
    </script>
{% endblock %}
                                                         